package com.easychat.entity.enums;

import com.easychat.utils.StringTools;
import jodd.util.StringUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * 账号类型 枚举类
 * @author kyle.li
 * @version 1.0
 * @description: TODO
 * @date 2024/7/1 20:05
 */
public enum UserContactTypeEnum {
    USER(0, "U", "好友"),
    GROUP(1, "G", "群");
    private Integer type;
    private String prefix;
    private String desc;

    UserContactTypeEnum(Integer type, String prefix, String desc){
        this.type = type;
        this.prefix = prefix;
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据名称，返回枚举对象
     * @param name
     * @return
     */
    public static UserContactTypeEnum getByName(String name){
        try{
            if(StringUtil.isEmpty(name)){
                return null;
            }
            return  UserContactTypeEnum.valueOf(name.toUpperCase());
        }catch (Exception e){
            return null;
        }
    }

    /**
     * 根据前缀 返回枚举对象
     * @param prefix
     * @return
     */
    public static UserContactTypeEnum getByPrefix(String prefix){
        try{
            if(StringUtil.isEmpty(prefix) || prefix.trim().length() == 0){
                return  null;
            }
            prefix = prefix.substring(0, 1);
            for(UserContactTypeEnum typeEnum : UserContactTypeEnum.values()){
                if(typeEnum.getPrefix().equals(prefix)){
                    return typeEnum;
                }
            }
            return  null;
        }catch (Exception e){
            return  null;
        }
    }

}
